package routines;

import org.hibernate.Session;
import org.hibernate.Query;

public class DAONotification extends DAO{
	
	public static Notification FindByNumber(String number) throws Exception{
		CheckSession();
		Query q = session.getNamedQuery("Notification.FindByNumber");
				//createQuery("from Notification where purchasenumber = :num");
		q.setString("num", number);
		Notification res = (Notification) q.uniqueResult();
		if (res!=null)
			res.setIsnew(false);
		return res;
	}
	
	public static Notification get(Long id){
		return (Notification) session.get(Notification.class, id);
	}
	
	public static void SaveNotificationDeleteSource(Object o, Long source_id) throws Exception{
		CheckSession();
		session.beginTransaction();
		session.saveOrUpdate(o);
		session.createSQLQuery("delete from stg_source_notifications where source_id =" + source_id.toString()).executeUpdate();
		session.getTransaction().commit();
		
	}

}
